// 账单查询类  
public class BillQuery {
    public void viewAllBills(PersonalBillManager.IncomeManager incomeManager, PersonalBillManager.ExpenseManager expenseManager) {
        System.out.println("\n所有账单：");
        System.out.println("收入：");
        for (PersonalBillManager.Bill bill : incomeManager.getIncomes()) {
            System.out.printf("日期: %s, 金额: %.2f, 类别: %s, 备注: %s%n", bill.date, bill.amount, bill.category, bill.note);
        }
        System.out.println("支出：");
        for (PersonalBillManager.Bill bill : expenseManager.getExpenses()) {
            System.out.printf("日期: %s, 金额: %.2f, 类别: %s, 备注: %s%n", bill.date, bill.amount, bill.category, bill.note);
        }
    }

    public void queryBills(String queryDate, String startDate, String endDate, String queryCategory, PersonalBillManager.IncomeManager incomeManager, PersonalBillManager.ExpenseManager expenseManager) {
        System.out.println("\n查询结果：");
        // 查询收入
        for (PersonalBillManager.Bill bill : incomeManager.getIncomes()) {
            if (matchesQuery(bill, queryDate, startDate, endDate, queryCategory)) {
                System.out.printf("收入 - 日期: %s, 金额: %.2f, 类别: %s, 备注: %s%n", bill.date, bill.amount, bill.category, bill.note);
            }
        }
        // 查询支出
        for (PersonalBillManager.Bill bill : expenseManager.getExpenses()) {
            if (matchesQuery(bill, queryDate, startDate, endDate, queryCategory)) {
                System.out.printf("支出 - 日期: %s, 金额: %.2f, 类别: %s, 备注: %s%n", bill.date, bill.amount, bill.category, bill.note);
            }
        }
    }

    private boolean matchesQuery(PersonalBillManager.Bill bill, String queryDate, String startDate, String endDate, String queryCategory) {
        boolean matches = true;
        if (queryDate != null && !queryDate.equals(bill.date)) {
            matches = false;
        }
        if (startDate != null && startDate.compareTo(bill.date) > 0) {
            matches = false;
        }
        if (endDate != null && endDate.compareTo(bill.date) < 0) {
            matches = false;
        }
        if (queryCategory != null && !queryCategory.equals(bill.category)) {
            matches = false;
        }
        return matches;
    }
}
